<?php
/*	echo '<p>Welcome To The Admin Page '.$username.'! All posts available for edit or deletion is listed below.</p><br/>';

	echo anchor('admin/create','Create New Post');

	$count = count($post['id']);
	for ($i=0;$i<$count;$i++)
	{
		echo '<div class="postDiv">';
		echo '<h4>'.$post['title'][$i];
		echo anchor('blog/view/'.$post['id'][$i],' [view]');
		echo anchor('admin/edit/'.$post['id'][$i],' [edit]');
		echo anchor('admin/delete/'.$post['id'][$i],' [delete]</h4>');
		echo '<p>'.$post['summary'][$i].'</p>';
		echo '</div>';
	}
*/?>

<!-- Main bar -->
<div class="mainbar">

<!-- Page heading -->
<div class="page-head">
    <h2 class="pull-left">Tables</h2>
    <div class="clearfix"></div>
    <!-- Breadcrumb -->
    <div class="bread-crumb">
        <a href="index.html"><i class="fa fa-home"></i> Home</a>
        <!-- Divider -->
        <span class="divider">/</span>
        <a href="#" class="bread-current">Tables</a>
    </div>

    <div class="clearfix"></div>

</div>
<!-- Page heading ends -->

<!-- Matter -->

<div class="matter">
<div class="container">

<!-- Table -->

<div class="row">

<div class="col-md-12">

<div class="widget">

    <div class="widget-head">
        <div class="pull-left">Tables</div>
        <div class="widget-icons pull-right">
            <a href="#" class="wminimize"><i class="fa fa-chevron-up"></i></a>
            <a href="#" class="wsettings"><i class="fa fa-wrench"></i></a>
            <a href="#" class="wclose"><i class="fa fa-times"></i></a>
        </div>
        <div class="clearfix"></div>
    </div>

    <div class="widget-content">
        <table class="table table-striped table-bordered table-hover" id="tblPost">
            <thead>
            <tr>
                <th>#</th>
                <th>Title</th>
                <th>Summary</th>
                <th>Content</th>
                <th>Date</th>
                <th>Action</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
</div>

</div>

</div>

</div>
</div>

<!-- Matter ends -->

</div>

<!-- Mainbar ends -->
<script>
    var ajax_datatable;

    $(document).ready(function() {
        ajax_datatable = $('table#tblPost').dataTable({
            "bServerSide": true,
            "bLengthChange": false,
            "bPaginate": false,
            "bFilter": false,
            "bInfo": false,
            "sAjaxSource": "<?php echo base_url(); ?>index.php/admin/ajax_datatable",
            "fnServerData": function(sSource,aoData,fnCallback)
            {
                aoData.push({name: "field2", value: '12334' });
                $.ajax({
                    "dataType": 'json',
                    "type": "POST",
                    "url": sSource,
                    "data": aoData,
                    "success": fnCallback
                });
            },
            "aoColumns": [
                { "sName": "id", "bSearchable": false, sDefaultContent: ""},
                { "sName": "title", sDefaultContent: "" },
                { "sName": "summary", sDefaultContent: "" },
                { "sName": "content", sDefaultContent: "" },
                { "sName": "created", sDefaultContent: "","sClass": "hidden-480" },
                { "sName": "id",
                    "bSortable": false,
                    "fnRender": function (oObj) {
                        return ' <button class="btn btn-xs btn-warning" onclick="EditPost(\'' + oObj.aData[0] + '\')"><i class="fa fa fa-pencil"></i> </button>'+
                        '<button class="btn btn-xs btn-danger" onclick="DeletePost(\'' + oObj.aData[0] + '\',\'DOC_TYPE\')"><i class="fa fa-times"></i> </button>';
                    }, sDefaultContent: ""
                }
            ]
        });
    });

    function EditPost(id)
    {
        window.location.href =  url+"admin/edit/"+id;
    }
    function DeletePost(id)
    {
        $.ajax({
            url: url+"admin/delete",
            type: "post",
            data: {id:id},
            success: function(){
                noty({text: 'Delete successful ...',layout:'topRight',type:'success',timeout:2000});
                ajax_datatable.fnDraw();
            },
            error:function(){
                alert("failure");
               // $("#result").html('There is error while submit');
            }
        });
    }

</script>


